﻿using DL.Characters.Player.FSM.StateMachine;
using UnityEngine;

namespace DL.Characters.Player.FSM.State
{
    /// <summary>
    /// 攻击准备阶段
    /// </summary>
    public class PlayerPreCombatState : PlayerCombatBaseState
    {
        public PlayerPreCombatState(PlayerCombatStateMachine playerStateMachine, int property = 0) : base(playerStateMachine, property)
        {
            
        }
        
        public override void Enter()
        {
            base.Enter();
            // Detection_Pre();
        }

        public override void StateTransitionCompleted()
        {
            if (!WeaponCombotController.ExecuteAttack_Pre())
            {
                StateMachine.ChangeState<PlayerCombatNullState>();
                return;
            }
            StateMachine.ChangeState<PlayerNormalCombatState>();
        }

        //范围探查
        private void Detection_Pre()
        {
            var count = CombatController.DetectionRangEnemy();
            Debug.Log("探测到敌人" + count);
            
            //探测到敌人
            if (count > 0)
            {
                ReusableData.CurrentTarget = CombatController.TryLockEnemy();
                CombatController.TryLookEnemy();
            }
        }
    }
}